<?php

namespace App\Observers;

use App\Models\Quiz;
use App\Models\QuizUser;

class QuizObserver
{

    /**
     * @param Quiz $quiz
     */
    public function creating(Quiz $quiz)
    {
        $quiz->user_id = request()->user()->id;
    }

    /**
     * @param Quiz $quiz
     */
    public function created(Quiz $quiz)
    {
        QuizUser::create([
            'quiz_id' => $quiz->id,
            'user_id' => $quiz->user_id,
        ]);
    }

    /**
     * @param Quiz $quiz
     */
    public function updated(Quiz $quiz)
    {
        $quiz->removeCache();
    }

    /**
     * @param Quiz $quiz
     */
    public function saved(Quiz $quiz)
    {
    }
}
